package com.zrar.ak.gkpt.controller.account;

import com.zrar.ak.gkpt.model.vo.UserVO;
import com.zrar.ak.gkpt.service.account.IBusinessAccountInfoService;
import com.zrar.ak.gkpt.service.user.IUserService;
import com.zrar.ak.gkpt.util.FormDataParameter;
import com.zrar.ak.gkpt.util.JsonPageResult;
import com.zrar.ak.gkpt.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * @ClassName: BusinessAccountInfoController
 * @Description 台账信息Controller层
 * @Author liyang
 * @Time 2020/02/25
 */
@RestController
@RequestMapping("/account")
@Api(tags = "台账信息相关接口")
public class BusinessAccountInfoController {

    @Autowired
    private IBusinessAccountInfoService businessAccountInfoService;
    @Autowired
    private IUserService userService;

    @RequestMapping(value = "basicInfoSave", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "台账基本信息保存", httpMethod = "POST", notes = "台账基本信息保存")
    public JsonResult accountBasicInfoSave(HttpServletRequest request,
                                             @ApiParam(name = "formDataParameter", value = "台账基本信息保存数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = businessAccountInfoService.accountBasicInfoSave(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "basicInfoUpdate", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "台账基本信息修改", httpMethod = "POST", notes = "台账基本信息修改")
    public JsonResult accountBasicInfoUpdate(HttpServletRequest request,
                                             @ApiParam(name = "formDataParameter", value = "台账基本信息修改数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = businessAccountInfoService.accountBasicInfoUpdate(jsonResult, formDataJson, userVO);
        return jsonResult;
    }


    @RequestMapping(value = "expandInfoSave", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "台账扩展信息保存", httpMethod = "POST", notes = "台账扩展信息保存")
    public JsonResult accountExpandInfoSave(HttpServletRequest request,
                                             @ApiParam(name = "formDataParameter", value = "台账扩展信息保存数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = businessAccountInfoService.accountExpandInfoSave(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "expandInfoUpdate", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "台账扩展信息修改", httpMethod = "POST", notes = "台账扩展信息修改")
    public JsonResult accountExpandInfoUpdate(HttpServletRequest request,
                                               @ApiParam(name = "formDataParameter", value = "台账扩展信息修改数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = businessAccountInfoService.accountExpandInfoUpdate(jsonResult, formDataJson, userVO);
        return jsonResult;
    }


    @RequestMapping(value = "accountInfoGet", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据单位ID获取台账信息", httpMethod = "GET", notes = "根据单位ID获取台账信息")
    public JsonResult accountInfoGetByUnitId(HttpServletRequest request,
                                                           @ApiParam(name = "unitId", value = "单位ID") @RequestParam String unitId){
        JsonResult jsonResult = new JsonResult();
        jsonResult = businessAccountInfoService.accountInfoGetByUnitId(jsonResult, unitId);
        return jsonResult;
    }

    @RequestMapping(value = "delete", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据单位ID将对应的台账信息置为无效", httpMethod = "GET", notes = "根据单位ID将对应的台账信息置为无效")
    public JsonResult deleteAccountInfoByUnitId(HttpServletRequest request,
                                                           @ApiParam(name = "unitId", value = "单位ID") @RequestParam String unitId,
                                                           @ApiParam(name = "accountType", value = "台账类型(1:台账基本信息和台账扩展信息 2:台账扩展信息)") @RequestParam(value = "accountType", required = false, defaultValue = "1") String accountType){
        JsonResult jsonResult = new JsonResult();
        jsonResult = businessAccountInfoService.deleteAccountInfoByUnitId(jsonResult, unitId, accountType);
        return jsonResult;
    }

    @RequestMapping(value = "getAccountInfoList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "获取台账信息列表-分页查询和条件查询", httpMethod = "GET", notes = "获取台账信息列表-分页查询和条件查询")
    public JsonPageResult getAccountInfoList(HttpServletRequest request,
                                                             @ApiParam(name = "currentPage", value = "当前页") @RequestParam int currentPage,
                                                             @ApiParam(name = "pageSize", value = "每页条数限制") @RequestParam int pageSize,
                                                             @ApiParam(name = "unitName", value = "单位名称(模糊查询)") @RequestParam(value = "unitName",required=false) String unitName){
        JsonPageResult jsonResult = new JsonPageResult();
        jsonResult = businessAccountInfoService.getAccountInfoList(jsonResult, currentPage,pageSize,unitName);
        return jsonResult;
    }


}
